﻿@inject IDataCacheService _dataCacheService
@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IUserService _userService
@inject NavigationManager NavigationManager


<MDCard Class="mb-8">
    <a class="image-link-card" href="@("lotteries/index/"+Model.Id)">
        <img class="image-card" src="@(_dataCacheService.IsApp?Model.MainPicture:Model.Thumbnail)" alt="@Model.Name" />
    </a>
    <div class="head-card">
        <div class="title-card">
            <h2 class="title-text">@Model.Name</h2>
            <dl class="info-card">
                <div>
                    <dt>参与人数：</dt>
                    <dd>@Model.Count</dd>
                </div>
                <div>
                    <dt>截止时间：</dt>
                    <dd>@Model.EndTime.ToString("yyyy年M月d日  H点")</dd>
                </div>
            </dl>
            <div class="text-card">
                @Model.BriefIntroduction
            </div>
        </div>
        <div class="content-card">

            <div class="condition-card">
                @if (Model.ConditionType == LotteryConditionType.Wishlist)
                {
                    <span>参与条件：把游戏 </span>

                    <a target="_blank" href="@($"https://store.steampowered.com/app/{Model.GameSteamId}")">加入Steam愿望单</a>
                }
                else
                {
                    @($"参与条件：{Model.ConditionType.GetDisplayName()}")
                }

            </div>
            <div class="button-card">
                @if (Model.EndTime < DateTime.Now.ToCstTime() || Model.IsParticipated)
                {
                    <CnGalWebSite.Components.Buttons.MasaButton Rounded Outlined Icon="@IconType.GiftOpened.ToIconString()" Text="查看抽奖" Href="@("lotteries/index/"+Model.Id)" />
                }
                else
                {
                    <AuthorizeView>
                        <Authorized>
                            <CnGalWebSite.Components.Buttons.MasaButton Rounded Icon="@IconType.Gift.ToIconString()" Text="参与抽奖" IsAsync OnClick="OnParticipateInLottery" />
                        </Authorized>
                        <NotAuthorized>
                            <CnGalWebSite.Components.Buttons.MasaButton Text="登入后参与抽奖" Rounded OnClick="_userService.Login" Icon="@IconType.Login.ToIconString()" />
                        </NotAuthorized>
                    </AuthorizeView>

                }
            </div>
        </div>
    </div>

</MDCard>
@if (Model.ShowError)
{
    <CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Type="AlertTypes.Error" Class="mb-8">
        Steam个人资料隐私设置<strong>【游戏详情】</strong>需要选择<strong>【公开】</strong>哦！<a href="/articles/index/5" target="blank" class="error--text fw-bold">点击阅读教程</a>
    </CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert>
}



@code {
    [Parameter]
    public LotteryCardViewModel Model { get; set; }


    [Parameter]
    public EventCallback OnParticipateInLottery { get; set; }


}
